<template>
	<view class="background">
		<view style="width:100%;height:28%; display: flex;align-items: center;justify-content: center;">
		  <view style="font-size: 22px;">
			  智慧校园
		  </view>
		</view>
		<view class="login-box">
			<view style="margin-left: 80rpx;">账号</view>
			<view><input class="login-input" v-model="username" placeholder=""/></view>
		</view>
		<view class="login-box">
			<view style="margin-left: 80rpx;">密码</view>
			<view><input class="login-input" v-model="password" placeholder=""/></view>
		</view>
		
		<view style="justify-content: center;">
			<button class="login-button" @click="login()">></button>
			<view style="font-size: 14px;margin-top: 80rpx;margin-left: 120rpx;;">我已阅读并同意<text style="color:#1696D1;">《服务协议》</text>和<text style="color:#1696D1;">《隐私政策》</text></view>
		</view>
	</view>
</template>

<script>
import request from '@/common/request.js';
import util from '@/api/util/index.js'
import {LoginForm} from '@/api/util/type.js'
import admin from '@/api/admin/index.js'
import store from '@/store';
	export default {
		data () {
			return {
			  username: '',
			  password: ''
			}
		},
		  onReady() {
			// const roleId = store.getters.getUserInfo?.roleId;
		  },
		methods: {
			async login() {
				try {
					  const loginData = {
						username: this.username,
						password: this.password
					  };
					const res = await util.login(loginData)
					console.log(res)
					if (res.message == null) {
						//保存登录信息
						store.dispatch('setToken', res.data.token);
						store.dispatch('setUserInfo', res.data.user);
            console.log(store.getters.getUserInfo)
            if (res.code == 208) {
              console.log('jump')
              uni.navigateTo({
                url: '/pages/login/changePassword',
              });
            }
            else {
              if (store.getters.getUserInfo.identity == 0) {
                uni.navigateTo({
                  url: '/pages/stuIndex/stuIndex',
                });
              }
              else if (store.getters.getUserInfo.identity == 1) {
                uni.switchTab({
                  url: '/pages/index/index',
                });
              }
              else {
                uni.navigateTo({
                  url: '/pages/adminIndex/adminIndex',
                });
              }
            }

					}
          else {
            uni.showModal({
              content: res.message,
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              success: (res) => {
              }
            });
          }
					// console.log(store.getters.getToken)
					// console.log(store.getters.getUserInfo)
				} catch(e){
					console.log(e)
				}


			  // uni.switchTab({
				// url: '/pages/myCourse/course'
			  // });
			},
		}
	}
</script>

<style>
.background {
	  height: 100vh; /* 使背景占满整个视口高度 */
	  width: 100%;
	  background: linear-gradient(to bottom, #DCE3F8, #FFFFFF); /* 从淡蓝色到灰色的渐变 */
	  flex-direction: column; /* 使子元素垂直排列 */
	  display: flex;

/* 	  align-items: center;
	  justify-content: center; */
}
.login-box {
	flex-direction: column; /* 使子元素垂直排列 */
	display: flex;
	margin: 0 1vh 4vh 1vh;
	width:100%;
	/* height:20%; */
}
.login-input {
	margin: 2vh 4vh 2vh 3vh;
	border-radius: 50px;
	background-color: #FFFFFF;
	height: 70rpx;
	/* width: 80%; */
	padding: 20rpx;
}
.login-button {
	width: 100rpx;
	height: 100rpx;
	border-radius: 50%;
	border: 0;
	background-color: #4C68E4;
	color: white;
	font-size: 22px;
	display: flex;
	box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3); /* 添加阴影效果 */
    align-items: center; /* 垂直居中对齐 */
	justify-content: center; /* 水平居中对齐 */
}
</style>